home *** CD-ROM | disk | FTP | other *** search
- package mx.utils
- {
- import flash.system.ApplicationDomain;
- import flash.utils.getQualifiedClassName;
- import mx.resources.ResourceBundle;
-
- public class Translator
- {
- private static const TRANSLATORS:Object = new Object();
-
- private static var dataBundle:ResourceBundle = ResourceBundle.getResourceBundle("data",ApplicationDomain.currentDomain);
-
- private static var messagingBundle:ResourceBundle = ResourceBundle.getResourceBundle("messaging",ApplicationDomain.currentDomain);
-
- private static var rpcBundle:ResourceBundle = ResourceBundle.getResourceBundle("rpc",ApplicationDomain.currentDomain);
-
- private static var utilsBundle:ResourceBundle = ResourceBundle.getResourceBundle("utils",ApplicationDomain.currentDomain);
-
- private var bundle:ResourceBundle = null;
-
- private var bundleName:String;
-
- public function Translator(param1:String)
- {
- bundle = null;
- super();
- this.bundleName = param1;
- }
-
- public static function getMessagingInstance() : Translator
- {
- return getInstanceFor("messaging");
- }
-
- public static function getDefaultInstanceFor(param1:Class) : Translator
- {
- var _loc2_:String = null;
- var _loc3_:int = 0;
- var _loc4_:int = 0;
- var _loc5_:int = 0;
- var _loc6_:String = null;
- _loc2_ = getQualifiedClassName(param1);
- _loc3_ = int(_loc2_.indexOf("."));
- _loc4_ = _loc3_ + 1;
- _loc5_ = int(_loc2_.indexOf(".",_loc4_));
- if(_loc5_ < 0)
- {
- _loc5_ = int(_loc2_.indexOf(":",_loc4_));
- }
- _loc6_ = _loc2_.slice(_loc4_,_loc5_);
- return getInstanceFor(_loc6_);
- }
-
- public static function getDataInstance() : Translator
- {
- return getInstanceFor("data");
- }
-
- public static function getInstanceFor(param1:String) : Translator
- {
- var _loc2_:Translator = null;
- _loc2_ = TRANSLATORS[param1];
- if(_loc2_ == null)
- {
- _loc2_ = new Translator(param1);
- TRANSLATORS[param1] = _loc2_;
- }
- return _loc2_;
- }
-
- public function textOf(param1:String, ... rest) : String
- {
- if(bundle == null)
- {
- if(bundleName == "data")
- {
- this.bundle = dataBundle;
- }
- else if(bundleName == "messaging")
- {
- this.bundle = messagingBundle;
- }
- else if(bundleName == "rpc")
- {
- this.bundle = rpcBundle;
- }
- else if(bundleName == "utils")
- {
- this.bundle = utilsBundle;
- }
- }
- return bundle == null ? "Key " + param1 + " was not found in resource bundle " + bundleName : StringUtil.substitute(bundle.getString(param1),rest);
- }
- }
- }
-
-